home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / uglbedt.exe / UGLBEDIT.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-01-10  |  5.7 KB  |  201 lines

  1. Unit UGlbEdit;
  2. interface
  3. uses WObjects,
  4.      WinTypes,
  5.      WinProcs,
  6.      StdWnds;
  7.  
  8. const
  9. SEGMENT=32760;
  10. { Creation window pointer for InitWndProc }
  11.   CreationWindow: PWindowsObject = nil;
  12.  
  13.   psSegProp: array[0..3] of Char = 'OW1';
  14.   psOfsProp: array[0..3] of Char = 'OW2';
  15.  
  16.  
  17. type
  18.   PGlbEdit = ^TGlbEdit;
  19.   TGlbEdit = object(TEdit)
  20.     wTextLength: word;
  21.     constructor Init(AParent: PWindowsObject;
  22.                 AnId: Integer; ATitle: PChar; X,Y,W,H, 
  23.                 ATextLen: Integer; Multiline : Boolean);
  24.     procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  25.     procedure SetupWindow; virtual;
  26.     function Create: boolean; virtual;
  27.   end;
  28.  
  29.   PBigFileWindow = ^TBigFileWindow;
  30.   TBigFileWindow = object(TFileWindow)
  31.     constructor Init(AParent: PWindowsObject; ATitle, AFileName: PChar);
  32.   end;
  33.  
  34. Implementation
  35. { Attach properties to provide a backup method retieving the object
  36.   pointer from a HWindow }
  37. procedure AttachProperties(HWindow: HWnd; Self: Pointer); assembler;
  38. asm
  39.     PUSH    HWindow
  40.         PUSH    DS
  41.         MOV    AX,OFFSET psSegProp
  42.         PUSH    AX
  43.         PUSH    Self.Word[2]
  44.         CALL    SetProp
  45.     PUSH    HWindow
  46.         PUSH    DS
  47.         MOV    AX,OFFSET psOfsProp
  48.         PUSH    AX
  49.         PUSH    Self.Word[0]
  50.         CALL    SetProp
  51. end;
  52.  
  53.  
  54. { Initialization window procedure }
  55.  
  56. function InitWndProc(HWindow: HWND; Message: Word; WParam: Word;
  57.   LParam: Longint): Longint; export; assembler;
  58. asm
  59.     PUSH    HWindow
  60.     MOV    AX,gwl_WndProc
  61.     PUSH    AX
  62.     LES    DI,CreationWindow
  63.     LES    DI,ES:[DI].TWindowsObject.Instance
  64.     PUSH    ES
  65.     PUSH    DI
  66.     CALL    SetWindowLong
  67.         PUSH    HWindow
  68.         LES    DI,CreationWindow
  69.         PUSH    ES
  70.         PUSH    DI
  71.         CALL    AttachProperties
  72.     PUSH    HWindow
  73.     PUSH    Message
  74.     PUSH    WParam
  75.     PUSH    LParam.Word[2]
  76.     PUSH    LParam.Word[0]
  77.     MOV    AX,DS
  78.     LES    DI,CreationWindow
  79.     CALL    ES:[DI].TWindowsObject.Instance
  80. end;
  81.  
  82. constructor TGlbEdit.Init(AParent: PWindowsObject;
  83.                           AnId: Integer; ATitle: PChar; X,Y,W,H, 
  84.                           ATextLen: Integer; Multiline : Boolean);
  85. begin
  86.   wTextLength := ATextLen;
  87.   TEdit.Init(AParent, AnId, ATitle, X,Y,W,H, ATextLen, MultiLine);
  88. end {constructor};    
  89.  
  90. { Specifies registration attributes for the MS-Windows window class of the
  91.   TWindow, allowing instances of TWindow to be registered.  Sets the fields
  92.   of the passed TWndClass parameter to the default attributes appropriate
  93.   for a TWindow. }
  94.  
  95. procedure TGlbEdit.GetWindowClass(var AWndClass: TWndClass);
  96. begin
  97.   AWndClass.cbClsExtra        := 0;
  98.   AWndClass.cbWndExtra        := 0;
  99.   AWndClass.hInstance        := HInstance;
  100.   AWndClass.hIcon        := LoadIcon(0, idi_Application);
  101.   AWndClass.hCursor        := LoadCursor(0, idc_Arrow);
  102.   AWndClass.hbrBackground    := HBrush(color_Window + 1);
  103.   AWndClass.lpszMenuName    := nil;
  104.   AWndClass.lpszClassName    := GetClassName;
  105.   AWndClass.style        := cs_HRedraw or cs_VRedraw;
  106.   AWndClass.lpfnWndProc       := @InitWndProc;
  107. end;
  108.  
  109. {    // This is done so that the limit text is done correctly.
  110.     // If you subclass TGlbEdit be sure to call this function just
  111.     // as TEdit::SetupWindow() is done below. }
  112. procedure TGlbEdit.SetupWindow;
  113. begin
  114.   TEdit.SetupWindow;
  115.   SendMessage(HWindow,EM_LIMITTEXT,wTextLength,0);
  116. end {procedure};
  117.  
  118.  
  119. function TGlbEdit.Create: Boolean;
  120. var
  121.   HParent: HWnd;
  122.   TheMDIClient: PMDIClient;
  123.   CreateStruct: TMDICreateStruct;
  124.   heditds: THandle;
  125.   hinst: THandle;
  126.   lpPtr: pointer;
  127. begin
  128.   if Status = 0 then
  129.   begin
  130.     DisableAutoCreate;
  131.     if Parent = nil then HParent := 0 else HParent := Parent^.HWindow;
  132.     if not IsFlagSet(wb_FromResource) then
  133.     begin
  134.       if Register then
  135.       begin
  136.         CreationWindow := @Self;
  137.         heditds := GlobalAlloc(
  138.                             GMEM_DDESHARE or GMEM_MOVEABLE or GMEM_ZEROINIT,
  139.                             SEGMENT
  140.                             );
  141.         {// if allocation fails then use the applications local heap}
  142.         if (heditds = 0)
  143.         then
  144.           hinst := hInstance
  145.         else begin 
  146.           lpPtr := GlobalLock(heditds);
  147.           {// Initialize a local heap in the segment}
  148.           LocalInit(HIWORD((LongInt(lpPtr))), 0, 
  149.                         WORD((GlobalSize(heditds) - 16)));
  150.           UnlockSegment(HIWORD(LONGINT(lpPtr)));
  151.           hinst := THandle(HIWORD(LONGINT(lpPtr)));
  152.         end;
  153.         if not IsFlagSet(wb_MDIChild) then
  154.           with Attr do
  155.             HWindow := CreateWindowEx(ExStyle, GetClassName, Title,
  156.               Style, X, Y, W, H, HParent, Menu, Hinst, Param)
  157.         else { MDI Child window }
  158.     begin
  159.       with CreateStruct do
  160.       begin
  161.         szClass := GetClassName;
  162.         szTitle := Attr.Title;
  163.         hOwner := Hinst;
  164.         x := Attr.X; y := Attr.Y; cx := Attr.W; cy := Attr.H;
  165.         style := Attr.Style;
  166.       end;
  167.       TheMDIClient := Parent^.GetClient;
  168.       if TheMDIClient <> nil then
  169.         HWindow := HWnd(SendMessage(TheMDIClient^.HWindow, wm_MDICreate, 0,
  170.           Longint(@CreateStruct)));
  171.     end; { MDI Child window }
  172.       end;
  173.     end
  174.     else { Windows already created window }
  175.       HWindow := GetDlgItem(HParent, Attr.ID);
  176.     if HWindow = 0 then
  177.       Status := em_InvalidWindow
  178.     else
  179.       if GetObjectPtr(HWindow) = nil then
  180.       begin
  181.         AttachProperties(HWindow, @Self);
  182.     DefaultProc := TFarProc(SetWindowLong(HWindow, gwl_WndProc,
  183.       LongInt(Instance)));
  184.     SetupWindow;
  185.       end;
  186.   end;
  187.   Create := Status = 0;
  188. end;
  189.  
  190. constructor TBigFileWindow.Init(AParent: PWindowsObject;
  191.                                 ATitle, AFileName: PChar);
  192. begin
  193.   TFileWindow.Init(AParent, ATitle, AFileName);
  194.   Dispose(Editor, Done);
  195.   Editor := New(PGlbEdit, Init(@Self, 200, nil, 0, 0, 0, 0, SEGMENT  , True));
  196.   with Editor^.Attr do
  197.     Style := Style or es_NoHideSel;
  198. end {constructor};
  199.  
  200. End.
  201.